package avicit.im.lantop.archiveplanmanager.archiveplanedit.action.rest;


import avicit.im.lantop.archiveplanmanager.archiveplanedit.action.service.ArchivePlanService;
import avicit.im.lantop.basic.archiveclassmanager.action.rest.ArchiveclassmanagerServiceRest;
import avicit.platform6.commons.utils.web.TreeNode;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "ArchivePlanService", description = "ArchivePlanServiceRest")
@RequestMapping("/api/avicit/im/lantop/archiveplanmanager/archiveplanedit/action/rest/ArchivePlanServiceRest")
public class ArchivePlanServiceRest {


    private static final Logger LOGGER = LoggerFactory.getLogger(ArchivePlanServiceRest.class);


    @Autowired
    private ArchivePlanService archivePlanService;

    /**
     * 迁移节点
     * @param param
     * @return
     */
    @PostMapping("/moveNode")
    @ApiOperation(value = "迁移节点")
    public ResponseMsg<Map<String, Object>> moveNode(@ApiParam(value = "迁移节点", name = "param") @RequestBody Map<String, Object> param) {
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();
        try {
            Map<String, Object> map = archivePlanService.moveNode(param);
            responseMsg.setResponseBody(map);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    @PostMapping("/findChildsByNodeId")
    @ApiOperation(value = "迁移节点")
    public ResponseMsg<List<TreeNode>> findChildsByNodeId(@ApiParam(value = "迁移节点", name = "id") @RequestBody String id) {
        ResponseMsg<List<TreeNode>> responseMsg = new ResponseMsg<>();
        try {
            List<TreeNode> childsByNodeId = archivePlanService.findChildsByNodeId(id);
            responseMsg.setResponseBody(childsByNodeId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }
}
